//<p>翻转一棵二叉树。</p>
//
//<p><strong>示例：</strong></p>
//
//<p>输入：</p>
//
//<pre>     4
//   /   \
//  2     7
// / \   / \
//1   3 6   9</pre>
//
//<p>输出：</p>
//
//<pre>     4
//   /   \
//  7     2
// / \   / \
//9   6 3   1</pre>
//
//<p><strong>备注:</strong><br>
//这个问题是受到 <a href="https://twitter.com/mxcl" target="_blank">Max Howell </a>的 <a href="https://twitter.com/mxcl/status/608682016205344768" target="_blank">原问题</a> 启发的 ：</p>
//
//<blockquote>谷歌：我们90％的工程师使用您编写的软件(Homebrew)，但是您却无法在面试时在白板上写出翻转二叉树这道题，这太糟糕了。</blockquote>
//<div><div>Related Topics</div><div><li>树</li><li>深度优先搜索</li><li>广度优先搜索</li><li>二叉树</li></div></div><br><div><li>👍 1146</li><li>👎 0</li></div>

package leetcode.editor.cn;

public class _226_InvertBinaryTree {
    public static void main(String[] args) {
        Solution solution = new _226_InvertBinaryTree().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode() {}
     * TreeNode(int val) { this.val = val; }
     * TreeNode(int val, TreeNode left, TreeNode right) {
     * this.val = val;
     * this.left = left;
     * this.right = right;
     * }
     * }
     */
    class Solution {
        public TreeNode invertTree(TreeNode root) {
            if (root == null) {
                return null;
            }
            TreeNode temp = root.left;
            root.left = root.right;
            root.right = temp;
            invertTree(root.left);
            invertTree(root.right);

            return root;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}